<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>palettemanager.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_equation_palettemanager.js.html">palettemanager.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2009 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.ui.equation.PaletteManager&#39;);
<a name="line16"></a>
<a name="line17"></a>goog.require(&#39;goog.Timer&#39;);
<a name="line18"></a>goog.require(&#39;goog.events.EventHandler&#39;);
<a name="line19"></a>goog.require(&#39;goog.events.EventTarget&#39;);
<a name="line20"></a>goog.require(&#39;goog.ui.equation.ArrowPalette&#39;);
<a name="line21"></a>goog.require(&#39;goog.ui.equation.ComparisonPalette&#39;);
<a name="line22"></a>goog.require(&#39;goog.ui.equation.GreekPalette&#39;);
<a name="line23"></a>goog.require(&#39;goog.ui.equation.MathPalette&#39;);
<a name="line24"></a>goog.require(&#39;goog.ui.equation.MenuPalette&#39;);
<a name="line25"></a>goog.require(&#39;goog.ui.equation.Palette&#39;);
<a name="line26"></a>goog.require(&#39;goog.ui.equation.SymbolPalette&#39;);
<a name="line27"></a>
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>/**
<a name="line31"></a> * Constructs the palette manager that manages all the palettes in Equation
<a name="line32"></a> * Editor.
<a name="line33"></a> * @constructor
<a name="line34"></a> * @extends {goog.events.EventTarget}
<a name="line35"></a> */
<a name="line36"></a>goog.ui.equation.PaletteManager = function() {
<a name="line37"></a>  goog.events.EventTarget.call(this);
<a name="line38"></a>
<a name="line39"></a>  /**
<a name="line40"></a>   * The map of palette type and instance pair.
<a name="line41"></a>   * @type {Object.&lt;string, goog.ui.equation.Palette&gt;}
<a name="line42"></a>   * @private
<a name="line43"></a>   */
<a name="line44"></a>  this.paletteMap_ = {};
<a name="line45"></a>
<a name="line46"></a>  /**
<a name="line47"></a>   * The current active palette.
<a name="line48"></a>   * @type {goog.ui.equation.Palette}
<a name="line49"></a>   * @private
<a name="line50"></a>   */
<a name="line51"></a>  this.activePalette_ = null;
<a name="line52"></a>
<a name="line53"></a>  /**
<a name="line54"></a>   * The event handler for managing events.
<a name="line55"></a>   * @type {goog.events.EventHandler}
<a name="line56"></a>   * @private
<a name="line57"></a>   */
<a name="line58"></a>  this.eventHandler_ = new goog.events.EventHandler(this);
<a name="line59"></a>
<a name="line60"></a>  /**
<a name="line61"></a>   * The timer used to add grace period when deactivate palettes.
<a name="line62"></a>   * @type {goog.Timer}
<a name="line63"></a>   * @private
<a name="line64"></a>   */
<a name="line65"></a>  this.deactivationTimer_ = new goog.Timer(300);
<a name="line66"></a>
<a name="line67"></a>  this.eventHandler_.listen(this.deactivationTimer_, goog.Timer.TICK,
<a name="line68"></a>      this.handleDeactivation_);
<a name="line69"></a>
<a name="line70"></a>};
<a name="line71"></a>goog.inherits(goog.ui.equation.PaletteManager,
<a name="line72"></a>    goog.events.EventTarget);
<a name="line73"></a>
<a name="line74"></a>
<a name="line75"></a>/**
<a name="line76"></a> * Clears the deactivation timer.  This is used to prevent palette manager
<a name="line77"></a> * deactivation when mouse pointer is moved outside palettes and moved back
<a name="line78"></a> * quickly inside a grace period.
<a name="line79"></a> */
<a name="line80"></a>goog.ui.equation.PaletteManager.prototype.stopDeactivation = function() {
<a name="line81"></a>  this.deactivationTimer_.stop();
<a name="line82"></a>};
<a name="line83"></a>
<a name="line84"></a>
<a name="line85"></a>/**
<a name="line86"></a> * Returns the palette instance of given type.
<a name="line87"></a> * @param {goog.ui.equation.Palette.Type} type The type of palette
<a name="line88"></a> *     to get.
<a name="line89"></a> * @return {goog.ui.equation.Palette} The palette instance of given
<a name="line90"></a> *     type. A new instance will be created.  If the instance doesn&#39;t exist.
<a name="line91"></a> */
<a name="line92"></a>goog.ui.equation.PaletteManager.prototype.getPalette =
<a name="line93"></a>    function(type) {
<a name="line94"></a>  var paletteMap = this.paletteMap_;
<a name="line95"></a>  var palette = paletteMap[type];
<a name="line96"></a>  if (!palette) {
<a name="line97"></a>    switch (type) {
<a name="line98"></a>      case goog.ui.equation.Palette.Type.MENU:
<a name="line99"></a>        palette = new goog.ui.equation.MenuPalette(this);
<a name="line100"></a>        break;
<a name="line101"></a>      case goog.ui.equation.Palette.Type.GREEK:
<a name="line102"></a>        palette = new goog.ui.equation.GreekPalette(this);
<a name="line103"></a>        break;
<a name="line104"></a>      case goog.ui.equation.Palette.Type.SYMBOL:
<a name="line105"></a>        palette = new goog.ui.equation.SymbolPalette(this);
<a name="line106"></a>        break;
<a name="line107"></a>      case goog.ui.equation.Palette.Type.COMPARISON:
<a name="line108"></a>        palette = new goog.ui.equation.ComparisonPalette(this);
<a name="line109"></a>        break;
<a name="line110"></a>      case goog.ui.equation.Palette.Type.MATH:
<a name="line111"></a>        palette = new goog.ui.equation.MathPalette(this);
<a name="line112"></a>        break;
<a name="line113"></a>      case goog.ui.equation.Palette.Type.ARROW:
<a name="line114"></a>        palette = new goog.ui.equation.ArrowPalette(this);
<a name="line115"></a>        break;
<a name="line116"></a>      default:
<a name="line117"></a>        throw new Error(&#39;Invalid palette type!&#39;);
<a name="line118"></a>    }
<a name="line119"></a>    paletteMap[type] = palette;
<a name="line120"></a>  }
<a name="line121"></a>  return palette;
<a name="line122"></a>};
<a name="line123"></a>
<a name="line124"></a>
<a name="line125"></a>/**
<a name="line126"></a> * Sets the palette instance of given type to be the active one.
<a name="line127"></a> * @param {goog.ui.equation.Palette.Type} type The type of the
<a name="line128"></a> *     palette to set active.
<a name="line129"></a> * @return {goog.ui.equation.Palette} The palette instance of given
<a name="line130"></a> *     type. A new instance will be created, if the instance doesn&#39;t exist.
<a name="line131"></a> */
<a name="line132"></a>goog.ui.equation.PaletteManager.prototype.setActive =
<a name="line133"></a>    function(type) {
<a name="line134"></a>  var palette = this.activePalette_;
<a name="line135"></a>  if (palette) {
<a name="line136"></a>    palette.setVisible(false);
<a name="line137"></a>  }
<a name="line138"></a>
<a name="line139"></a>  palette = this.getPalette(type);
<a name="line140"></a>  this.activePalette_ = palette;
<a name="line141"></a>  palette.setVisible(true);
<a name="line142"></a>
<a name="line143"></a>  return palette;
<a name="line144"></a>};
<a name="line145"></a>
<a name="line146"></a>
<a name="line147"></a>/**
<a name="line148"></a> * Returns the active palette.
<a name="line149"></a> * @return {goog.ui.equation.Palette} The active palette.
<a name="line150"></a> */
<a name="line151"></a>goog.ui.equation.PaletteManager.prototype.getActive = function() {
<a name="line152"></a>  return this.activePalette_;
<a name="line153"></a>};
<a name="line154"></a>
<a name="line155"></a>
<a name="line156"></a>/**
<a name="line157"></a> * Starts the deactivation of open palette.
<a name="line158"></a> * This method has a slight delay before doing the real deactivation.  This
<a name="line159"></a> * helps prevent sudden disappearing of palettes when user moves mouse outside
<a name="line160"></a> * them just briefly (and maybe accidentally).  If you really want to deactivate
<a name="line161"></a> * the active palette, use {@link #deactivateNow()} instead.
<a name="line162"></a> */
<a name="line163"></a>goog.ui.equation.PaletteManager.prototype.deactivate = function() {
<a name="line164"></a>  this.deactivationTimer_.start();
<a name="line165"></a>};
<a name="line166"></a>
<a name="line167"></a>
<a name="line168"></a>/**
<a name="line169"></a> * Deactivate the open palette immediately.
<a name="line170"></a> */
<a name="line171"></a>goog.ui.equation.PaletteManager.prototype.deactivateNow = function() {
<a name="line172"></a>  this.handleDeactivation_();
<a name="line173"></a>};
<a name="line174"></a>
<a name="line175"></a>
<a name="line176"></a>/**
<a name="line177"></a> * Internal process of deactivation of the manager.
<a name="line178"></a> * @private
<a name="line179"></a> */
<a name="line180"></a>goog.ui.equation.PaletteManager.prototype.handleDeactivation_ = function() {
<a name="line181"></a>  this.setActive(goog.ui.equation.Palette.Type.MENU);
<a name="line182"></a>};
<a name="line183"></a>
<a name="line184"></a>
<a name="line185"></a>/** @override */
<a name="line186"></a>goog.ui.equation.PaletteManager.prototype.disposeInternal = function() {
<a name="line187"></a>  goog.base(this, &#39;disposeInternal&#39;);
<a name="line188"></a>  this.activePalette_ = null;
<a name="line189"></a>  this.paletteMap_ = null;
<a name="line190"></a>};
</pre>


</body>
</html>
